package cn.easybuy.web.pre;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.easybuy.dao.ProductCategoryDao;
import cn.easybuy.dao.impl.ProductCategoryDaoImpl;
import cn.easybuy.entity.Product;
import cn.easybuy.entity.ProductCategory;
import cn.easybuy.service.ProductService;
import cn.easybuy.service.impl.ProductServiceImpl;

public class BrandListServlet extends HttpServlet {

	@Override
	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String id3 = request.getParameter("id3");
		String name3 = request.getParameter("name3");
		ProductCategoryDao prDao = new ProductCategoryDaoImpl();
		String name2 = prDao.getParantNameById(Integer.parseInt(id3));
		String name1 = prDao.getGrandParantNameById(Integer.parseInt(id3));
	
		ProductService pService = new ProductServiceImpl();
		List<Product> prList = pService.getProductsByCategoryLevel3Id(Integer.parseInt(id3));
		
		int number = prList.size();
		request.setAttribute("number", number);
		request.setAttribute("name1", name1);
		request.setAttribute("name2", name2);
		request.setAttribute("name3", name3);
		request.setAttribute("prList", prList);
		request.getRequestDispatcher("BrandList.jsp").forward(request, response);

	}

}
